require(["common", "jQuery", "coAjax", "queryString", "href", "hash_routie"], function(jSouper, $, coAjax, QueryString, href, hash_routie) {
	//INIT
	var TICKET_FACTORY_TYPE_array = [];
	jSouper.forEach(appConfig.TICKET_FACTORY_TYPE, function(value, key) {
		TICKET_FACTORY_TYPE_array.push({
			key: key,
			value: value
		});
	});
	App.set("$Cache.TICKET_FACTORY_TYPE_array", TICKET_FACTORY_TYPE_array);

	hash_routie.on("ticket_factory", function() {
		coAjax.get(appConfig.bus.ticket_factory_list, function(result) {
			App.set("$Cache.bus.ticket_factory.list", result.result)
		});
	});

	App.set("$Event.bus.ticket_factory.add_ticket_factory", function(e) {
		coAjax.post(appConfig.bus.ticket_factory_add, App.get("$Cache.bus.ticket_factory.new"), function(result) {
			alert("优惠券添加成功");
			var ticket_factory_list = App.get("$Cache.bus.ticket_factory.list");
			ticket_factory_list.unshift(result.result);
			App.set("$Cache.bus.ticket_factory.list", ticket_factory_list)
		});
	});

	App.set("$Event.bus.ticket_factory.remove_ticket_factory", function(e, vm) {
		myConfirm("确定要删除这个优惠券？", function() {
			coAjax["delete"](appConfig.bus.ticket_factory_remove + vm.get("_id"), function(result) {
				alert("优惠券删除成功");
				App.set("$Cache.bus.ticket_factory.list", result.result)
			});
		});
	});
});